#!/bin/bash

exitRC=0
logFile=/tmp/hmc_install.log

#-------------------------------------------------------------------------------
# Common exit point
#-------------------------------------------------------------------------------
exit_cleanup() {

   exit $1$exitRC
}

#-------------------------------------------------------------------------------
# RPM  install
#-------------------------------------------------------------------------------
dorpm() {

   if [ -f /opt/hsc/data/config/NO_UPDATE_RPMS ]
   then
     x="$2"
# Strip version then leading directory name
     f=`echo ${x%%-[0-9]*}`
     r=`echo ${f##*/}`
     for i in `cat /opt/hsc/data/config/NO_UPDATE_RPMS`
     do
       if [ "$r" = "$i" ]
       then
          return
       fi
     done
   fi
     
   # Log the test install output. The format for the "normal" RPM install
   # processing inside this script is 'rpm -i <file spec> --force --nodeps'
   rpm $* 2>> $logFile
   RC=$?
   return $RC
}

#-------------------------------------------------------------------------------
# Start the product install...
#-------------------------------------------------------------------------------
cd /
image=$1

if [ "$image" = "" ]
then
   echo "Please specify directory containing installable packages"
   echo "usage: installImages  <directory>"
   exit_cleanup 1
fi

# check if directory exists
if [ ! -d $image ]
then
 echo "The directory $patchdir doesn't exist"
 echo "Please specify directory containing the installable packages."
 exit_cleanup 2
fi

if [ -f /opt/hsc/data/config/NO_UPDATE_FILES ]
then
   rm -f /tmp/saved_files.tar
   cat /opt/hsc/data/config/NO_UPDATE_FILES | xargs tar -cvf /tmp/saved_files.tar
fi

PATH=$PATH:/opt/IBMJava/jre/bin:
LD_LIBRARY_PATH=/opt/hsc/lib:/opt/hsc/lib/hcmjni:/lib:/usr/lib:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH

LANG=en_US
export LANG
LANG=en_US
export LANG
r=`/opt/hsc/bin/hsc version | grep Release`
rr=`echo $r | cut -d':' -f2 | cut -d'.' -f1`
case "$rr" in
  " 2" )
   rel=2
   ;;
  " 3" )
   rel=3
   ;;
  " 4" )
   rel=4
   ;;
  * )
   rel=UNKNOWN
   ;;
esac
if [[ "$rel" == "2" || "$rel" == "3" || "$rel" == "4" ]]; then
   echo "--- Installing MH00220 -----"
   cp $image/startWizard /opt/hsc/bin/
   chown bin.bin /opt/hsc/bin/startWizard
   chmod 555 /opt/hsc/bin/startWizard

   grep -q "MH00220: Guided Setup Security fix (02-07-2005)" /opt/hsc/data/version
   if [ $? -ne 0 ]
   then
      echo "MH00220: Guided Setup Security fix (02-07-2005)" >> /opt/hsc/data/version
   fi
else
  echo "--- Cannot install this fix on this level of code ---"
fi
exit_cleanup 0
